using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpaceInvaders
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        public static SpriteFont testFont;
        GerenciadorDeCena gerenciadorDeCena;
        KeyboardState kState;
        MouseState mState;
        public static bool exit;
        
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }


        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();
            IsMouseVisible = true;
            base.Initialize();            
        }


        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            gerenciadorDeCena = new GerenciadorDeCena(Content, graphics);
            GerenciadorDeTiro.textureEnemy = Content.Load<Texture2D>(@"Imagens\tiroOibaf");
            GerenciadorDeTiro.texturePlayer = Content.Load<Texture2D>(@"Imagens\tiroSIR");
            testFont = Content.Load<SpriteFont>("arial");
            Ranking.BACKGROUND = Content.Load<Texture2D>(@"Imagens\Intro");
            Ranking.FONT = Content.Load<SpriteFont>("arial");
            Ranking.VOLTAR = new Icon(Content.Load<Texture2D>(@"Imagens\bot_voltar"), new Vector2(700, 530));
            TecladoVirtual.Load(Content.Load<Texture2D>(@"Imagens\teclado"));
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            if (exit)
                this.Exit();

            kState = Keyboard.GetState();
            mState = Mouse.GetState();

            gerenciadorDeCena.Update(kState, gameTime, mState);

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();    
        
            gerenciadorDeCena.Draw(spriteBatch);
            if (GerenciadorDeTiro.playerShots != null && GerenciadorDeInimigo.enemies != null)
                spriteBatch.DrawString(testFont, " " + GerenciadorDeTiro.playerShots.Length + "\n" + GerenciadorDeInimigo.enemies.Length, new Vector2(20, 20), Color.Red);
            
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
